//
//  main.cpp
//  SOC
//
//  Created by Benson Tran on 1/6/13.
//  Copyright (c) 2013 Benson Tran. All rights reserved.
//


#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include "core.h"
using namespace std;


int main(int argc, char* argv[])
{
    //Initialize CoreArray
    
    int counter = 0;
    int N, Wmax, Pmax;
    int W,T,w,t,p;
    core* coreArray;
    int powerholder;
       
    ifstream chip (argv[1]);
    
    chip >> Pmax >> Wmax >> N; // Change the format of the text file
    
    cout << "N: " << N << endl;
    
//    cout << N; cout << Wmax;
    
    if (!chip.is_open()) {
    	cout << "Error opening file" << endl;
    	return -1;
    }

    for (int i = 0; i< N; i++){
        
        chip >> p >> W >> T >> w >> t;
//        cout << W;
//        cout << T;
//        cout << w;
//        cout << t;
        coreArray[i].init(p,W,T,w,t);

    }
    
    chip.close();
    cout << "init done"<< endl;
    //Test 1: Determine whether Wmax is violated.
    
    core::wmaxtest(coreArray, Wmax, N);
    
    //Test 2: Determine whether any cores overlap.
    
    core::overlap(coreArray, Wmax, N);
    
    
    //Test 3: Determine the makespan:
    
    int span = core::makespan(coreArray, N);
    
    //Test 4: Powercheck
    
    core::powercheck(coreArray, Pmax, N, &powerholder);
    
    //Color Cores
    
    string Color[] = {"RoyalBlue", "Cerulean", "Goldenrod", "OrangeRed", "BurntOrange", "Emerald", "Lavender", "LimeGreen", "Black", "Fuchsia"
        "Periwinkle", "Yellow", "OliveGreen", "Gray", "Tan", "MidnightBlue"};
    
    core::coloring(coreArray, Color, N);
    
    
    //Output .tex File
    
    core::latex(coreArray, N, Wmax, span);
    
    //Output .m File
    
    core::plot(coreArray, N, powerholder, Pmax);
    
    return 0;
    
}

